package com.coolw.test.sftp.monitor;

import com.coolw.test.sftp.SftpClient;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * SftpMain
 *
 * @author coolw
 * @date 2024/5/8 19:10
 */
public class SftpMain {

    SftpClient client = null;
    ChannelSftp channelSftp = null;

    String src = "D:\\javaspace\\maven\\apache-maven-3.6.3\\repository\\io\\kyoto.zip";
    String dst = "/coolw/kyoto.zip";

    @Before
    public void before() throws JSchException {
        client = new SftpClient();
        channelSftp = client.getChannel();
    }

    @After
    public void after() {
        if (client != null) {
            client.closeChannel();
        }
    }

    @Test
    public void testPut() throws SftpException {
        channelSftp.put(src, dst, ChannelSftp.OVERWRITE);
    }

    @Test
    public void testPutMonitor1() throws SftpException {
        channelSftp.put(src, dst, new MySftpProgressMonitor(), ChannelSftp.OVERWRITE);
    }

    @Test
    public void testPutMonitor2() throws SftpException {
        channelSftp.put(src, dst, new TimeSftpProgressMonitor(), ChannelSftp.OVERWRITE);
    }

    @Test
    public void testPutMonitor3() throws SftpException {
        channelSftp.put(src, dst, new TimeSftpProgressMonitor1(), ChannelSftp.OVERWRITE);
    }

    @Test
    public void testPutMonitor4() throws SftpException {
        channelSftp.put(src, dst, new TimeSftpProgressMonitor2(), ChannelSftp.OVERWRITE);
    }
}
